from time import sleep

import pytest
from selenium import webdriver

from common.mysql_tools import connect, execute, disconnect


@pytest.fixture(scope="session")
def database_clean():
    a = connect()
    # 常见错误 port 整数  pwd 字符串   charset utf8 不是 utf-8
    # print(execute(a, "select * from xqdsys_user "))
    print(execute(a, "insert into xqdsys_user (account,password)values('test9529',MD5('123456')) "))
    # print(execute(a, "select * from xqdsys_user "))
    disconnect(a)


@pytest.fixture()
def get_driver():
    # 前置方法
    driver = webdriver.Chrome()
    driver.maximize_window()
    sleep(2)
    driver.get("http://localhost/ranzhi/www/sys/user-login-L3JhbnpoaS93d3cvc3lzLw==.html")
    yield driver
    # 后置方法
    driver.close()
    driver.quit()